package cn.strive.eams.building.service.impl;

import cn.strive.eams.building.mapper.BuildMapper;
import cn.strive.eams.building.pojo.dto.BuildQuery;
import cn.strive.eams.building.pojo.dto.BuildingSaveParam;
import cn.strive.eams.building.pojo.entity.Build;
import cn.strive.eams.building.pojo.vo.BuildVO;
import cn.strive.eams.building.service.BuildService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class BuildServiceImpl implements BuildService {
    @Autowired
    BuildMapper buildMapper;
    @Override
    public List<BuildVO> selectBuild(BuildQuery buildQuery) {
        log.debug("查询所有楼宇信息,参数:{}",buildQuery);
        List<BuildVO> list = buildMapper.selectBuild(buildQuery);
        return list;
    }

    @Override
    public void saveBuild(BuildingSaveParam buildingSaveParam) {
        log.debug("保存楼宇信息:buildingSaveParam:{}",buildingSaveParam);
        Build build = new Build();
        BeanUtils.copyProperties(buildingSaveParam,build);
        if (build.getId() == null){
            build.setCreateTime(new Date());
            buildMapper.insert(build);
        }else {
            build.setUpdateTime(new Date());
            buildMapper.update(build);
        }
    }

    @Override
    public void deleteBuild(Long id) {
        log.debug("删除楼宇信息:id={}",id);
        buildMapper.delete(id);
    }
}
